//
//  MNDIntegralViewController.m
//  minidai
//
//  Created by Steven.Yung on 2017/5/27.
//  Copyright © 2017年 迷你贷. All rights reserved.
//

#import "MNDIntegralViewController.h"
#import "MNDExchangeAlertViewController.h"
#import "MNDWebViewController.h"

@interface MNDIntegralViewController ()

@property (weak, nonatomic) IBOutlet UILabel *myTotalScoreLabel;

@end

@implementation MNDIntegralViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.myTotalScoreLabel.text = self.myTotalScore;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initialBarbuttonItems {
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                target:nil action:nil];
    //将宽度设为负值
    spaceItem.width = -15;
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"积分规则"
                                                             style:UIBarButtonItemStylePlain
                                                            target:self
                                                            action:@selector(clickScoreRegularBtn:)];
    [item setTitleTextAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:14.0]} forState:UIControlStateNormal];
    [item setTintColor:kColorBlack];
    
    self.navigationItem.rightBarButtonItems = @[spaceItem, item];
}

//点击积分规则
- (void)clickScoreRegularBtn:(UIBarButtonItem *)sender {
    MNDWebViewController *webVC = [[MNDWebViewController alloc]init];
    webVC.naviBarHidden = YES;
    webVC.webViewUrl = [NSString stringWithFormat:@"%@%@",kWebBaseURLStr,kScoreRegular];
    [self.navigationController pushViewController:webVC animated:YES];
    
    
}

- (IBAction)exchangeIntegralAction:(id)sender {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    __weak MNDExchangeAlertViewController *alertVC = [storyboard instantiateViewControllerWithIdentifier:@"MNDExchangeAlertViewController"];
    __weak UIView *springView = alertVC.view;
    alertVC.myTotalScore = self.myTotalScore;
    alertVC.canUseScoreLabel.text = [NSString stringWithFormat:@"可用积分:%@",self.myTotalScore];
    [KeyWindow addSubview:springView];
    [self addChildViewController:alertVC];
    //    __weak typeof(self) weakSelf = self;
    [alertVC.closeScoreButton bk_addEventHandler:^(id sender) {
        [springView removeFromSuperview];
        [alertVC removeFromParentViewController];
    } forControlEvents:UIControlEventTouchUpInside];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
